/**
 * @program: LeetCode
 * @description: LeetCode : 416. 分割等和子集
 * @author: WXY
 * @create: 2023-01-26 14:09
 * @Version 1.0
 **/
public class Num416_canPartition {
    public static boolean canPartition(int[] nums) {
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        if (sum % 2 == 1) return false;
        int targe = sum / 2;
        int[] dp = new int[targe + 1];
        for (int i = 0; i < nums.length; i++) {
            for (int j = targe; j >= 0; j--) {
                dp[j] = Math.max(dp[j], dp[j - nums[j]] + nums[j]);
            }
        }
        return dp[targe] == targe;
    }
    
}
